

const util = require('../../utils/util.js');
import { areaList } from './../../miniprogram_npm/@vant/area-data/index';
Page({
  /**
   * 页面的初始数据
   */
  data: {
    name: '',
    mobile: '',
    address: '',
    remark: '',

    province: '',
    city: '',
    region: '',

    showAc: false,
    areaList: areaList
  },


  doSubmit() {
    // wx.navigateTo({ url: '/page2/result/index' })
    // return
    let sData = this.data;
    console.log(sData)
    let postData = {
      "name": sData.name,
      "mobile": sData.mobile,
      "remark": sData.remark,
      "address": sData.address
    };
    if (postData.name == '' || postData.name == null) {
      wx.showModal({
        title: '温馨提示',
        content: '姓名不能为空！',
        confirmColor: '#F08302',
        showCancel: false,
        success(res) {
        }
      })
      return
    }
    if (!/^1[3456789]\d{9}$/.test(postData.mobile)) {
      console.log('电话号码不正确！')
      wx.showModal({
        title: '温馨提示',
        content: '电话号码不正确！',
        confirmColor: '#F08302',
        showCancel: false,
        success(res) {
        }
      })
      return
    }
    if (postData.address == '' || postData.address == null) {
      wx.showModal({
        title: '温馨提示',
        content: '选择区域不能为空！',
        confirmColor: '#F08302',
        showCancel: false,
        success(res) {
        }
      })
      return
    }
    util.https('partner/partnerAdd', postData, (res) => {
      console.log(res)
      wx.redirectTo({
        url: '/page2/result/index',
      })
    }, (res) => {
      console.log(res)
      wx.showModal({
        title: '温馨提示',
        content: res.errorMsg,
        confirmColor: '#F08302',
        showCancel: false,
        success(res) {
        }
      })
    })
  },
  onClickIcon() {
    this.setData({
      showAc: true
    })
  },
  cancelAc() {
    this.setData({
      showAc: false
    })
  },
  confirmAc(ss) {
    console.log(ss)
    let item = ss.detail.values;
    this.setData({
      province: item[0].name,
      city: item[1].name,
      region: item[2].name,
      address: item[0].name + "/" + item[1].name + "/" + item[2].name,
      showAc: false
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  
})